import java.util.ArrayList;
import java.util.List;

public class test1 {
    public List<Integer> findAnagrams(String ss, String pp){
        List<Integer> ret = new ArrayList<>();
        char[] s = ss.toCharArray();
        char[] p = pp.toCharArray();

        int[] hash1 = new int[26];
        for(char c: p){
            hash1[c-'a']++;
        }

        int[] hash2 = new int[26] ;
        int left = 0;
        int right = 0;
        int n = s.length;
        int m = p.length;
        int count = 0;
        for(;right<n;right++){
            char in = s[right];
            hash2[in-'a']++;
            if(hash2[in-'a']<=hash1[in-'a']){
                count++;
            }
            if(right-left+1>m){
                char out = s[left];
                left++;
                if(hash2[out-'a']<=hash1[out-'a']){
                    count--;
                }
                hash2[out-'a']--;
            }

            if(count==m){
                ret.add(left);
            }
        }
        return ret;
    }
}
